# -!- coding: utf-8 -!-
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
获取规则引擎当中的非自定义数据 
http://10.16.20.202/risk/trics/undefinedVariable/query?current=1&sortType=desc&limit=10 获取count总数量count
然后limit=count查询所有的数据
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

import requests
from pycacho.cachobase.file_deal import an_save_txt

url = 'http://10.16.20.202/risk/trics/undefinedVariable/query?current=1&sortType=desc&limit='           # 测试
#url = 'http://10.16.20.211/risk/trics/undefinedVariable/query?current=1&sortType=desc&limit='          # 生产

headers = {
            'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.80 Safari/537.36',
            'content-Type': 'application/json',
            #"Cookie": "_preference=eyJkZWxldGVkIjowLCJsYW5ndWFnZSI6MCwiaWQiOjIzNCwidXNlcklkIjoxOTh9JmRhMTQxM2M1M2RmNDZmMTE0ZjhiMmE2NjlkN2Y1Y2Q3MWJlNjM4NGU4YWY0ZjcyZWJjNDAwM2ZjNmQ3YmUwYzY=; _risk_user=d2VuOjE5ODoxOjE1NjQwNjMzOTYzNTI6MDpkNzRlMjIxNTY4YmNiMTVmYzFhOWYzMTcyNjY2YjYyYzJkNGE5ZTY4OGNlMzJkM2UwZDhhOTMzNjU2M2ZkYTBl; _risk_user_extension=; nav_toggle=show"
            "Cookie": "_preference=eyJkZWxldGVkIjowLCJsYW5ndWFnZSI6MSwiaWQiOjIzNSwidXNlcklkIjoxOTl9JjIyMDVkNWRmMDFmNzE3ZDU0YmI5Y2FlMjlkMmNjODI4NjI1YmI2M2QwZTI3ZGZlNDJkNzNkNTg5OWFkNTFhZmM=; _risk_user_extension=; _risk_user=5p6X5a6d5aWHOjE5OToxOjE1Njg5MTk1NzMxOTA6MDoyMTQ3NzBjMTI1ZDQ2OTcxYWRmOGYwNTNhMDlmMGFlZDUyZTc5ODFiZjYwNGZlODkwNzM1MTU5MTllNTY5MDNm"
    }

# 上传到规则引擎的
info ={
    "aiChongApplyAmount":"501230.00",
    "aiChongConfirmGMV":"0",
    "aiChongContact1Relation":"1",
    "aiChongContact2Relation":"5",
    "aiChongDownPaymentAmount":"502220.00",
    "aiChongEquipmentAmount":"138000.00",
    "aiChongInstallmentTerm":"12",
    "aiChongPurchaseMode":"1",
    "aiChongRefundGMV":"0",
    "aiChongRegisteredDays":"DEFAULT",
    "appId":"60F7B478D66C036ABDBBD8F3C3F1714B",
    "baiHangTel3Verify":"DEFAULT",
    "creditAge":"31",
    "creditBlkBankCardHitBankCard":"-989",
    "creditBlkIdCardHitIdCard":"-989",
    "creditBlkMblNoHitMblNo":"-989",
    "creditCusSex":"1",
    "creditIdCardPD":"5646",
    "creditMaritalSta":"1",
    "dianHuaBangTelConsume":"12",
    "dianHuaBangTelOperation":"移动",
    "dianHuaBangTelPeriod":"5",
    "dianHuaBangTelStatus":"2",
    "faceLiteLivenessResult":"PASS",
    "faceLiteResultFaceidConfidence":"93.039",
    "idcard":"36242219881103431X",
    "mobile":"15917374871",
    "name":"曾令为",
    "pengYuanPersonalSolvency":"经评估，预计未来12个月个人年偿债能力约为10.8-13.2万元/年。",
    "processNo":"PRO202009221928166554107781",
    "qiChaChaAdminPunNo":"-989",
    "qiChaChaAnnoReminderCountNo":"-989",
    "qiChaChaCompStatus":"开业",
    "qiChaChaCourtAnno":"-989",
    "qiChaChaCourtNotice":"-989",
    "qiChaChaEnvPunishCountNo":"-989",
    "qiChaChaEquityFreezeCountNo":"-989",
    "qiChaChaEquityPleCountNo":"-989",
    "qiChaChaExceptionCountNo":"1",
    "qiChaChaJudicialCountNo":"-989",
    "qiChaChaLandPledgeCountNo":"-989",
    "qiChaChaLawFileCountNo":"-989",
    "qiChaChaLiquidation":"-989",
    "qiChaChaMPledgeCountNo":"-989",
    "qiChaChaOperName":"阮芳",
    "qiChaChaQueryResult":"Y",
    "qiChaChaSeriousCountNo":"-989",
    "qiChaChaShiXinItems":"0",
    "qiChaChaSimCancelCountNo":"-989",
    "qiChaChaStartMonth":"63",
    "qiChaChaTaxOweCountNo":"-989",
    "qiChaChaTaxVioCountNo":"-989",
    "qiChaChaTeamEndMonth":"536",
    "qiChaChaZhiXingItems":"0",
    "sign":"1ACF08FD7FC4E46B2E8602076225BFD2",
    "tencentCloudBankCard4Verify":"Y",
    "tencentRiskCode1101":"N",
    "tencentRiskCode1102":"N",
    "tencentRiskCode1103":"N",
    "tencentRiskCode1104":"N",
    "tencentRiskCode1105":"N",
    "tencentRiskCode1106":"N",
    "tencentRiskCode1107":"N",
    "tencentRiskCode1108":"N",
    "tencentRiskCode1201":"N",
    "tencentRiskCode3101":"N",
    "tencentRiskCode3103":"N",
    "tencentRiskCode3104":"N",
    "tencentRiskCode3202":"N",
    "tencentRiskScore":"34",
    "tongDunEmailNumberCount":"0",
    "tongDunFraudPoints":"2",
    "tongDunFuzzyList":"N",
    "tongDunIdNumberCount":"0",
    "tongDunIdNumberHighFocusList":"N",
    "tongDunJusticeRepresentList":"N",
    "tongDunLoseFuzzyList":"N",
    "tongDunLoseList":"N",
    "tongDunLowFocusList":"Y",
    "tongDunMiddleFocusList":"N",
    "tongDunOneMonthPlatfromNumber":"0",
    "tongDunOverdueFuzzyList":"N",
    "tongDunOverdueList":"N",
    "tongDunOwingHistory":"N",
    "tongDunOwingTaxesList":"N",
    "tongDunPerformFuzzyList":"N",
    "tongDunPerformList":"N",
    "tongDunPhoneHighFocusList":"N",
    "tongDunPhoneNumberCount":"0",
    "tongDunPhoneOverdueList":"N",
    "tongDunPhoneRepaymentList":"N",
    "tongDunRepaymentList":"N",
    "tongDunRepresentList":"N",
    "tongDunSettleLawsuitList":"N",
    "tongDunSpuriousLibrary":"N",
    "tongDunThreeMonthIdNumberCount":"0",
    "tongDunThreeMonthPhoneCount":"0",
    "tongDunThreeMonthPlatfromNumber":"0",
    "tongDunThreeMonthSpouseIdNumberCount":"0",
    "tongDunThreeMonthSpousePhoneCount":"0",
    "tongDunTrumpetLibrary":"N",
    "tongDunWantedList":"N",
    "tongDunWeekPlatfromNumber":"0",
    "unionPReportHarvestCP0238":"-989",
    "unionPReportHarvestCP2001":"-989",
    "unionPReportHarvestCP2016":"-989",
    "unionPReportHarvestCP3001":"-989",
    "unionPReportHarvestCP3016":"-989",
    "unionPReportHarvestCP3218":"-989",
    "unionPReportHarvestCP3227":"-989",
    "unionPReportHarvestCP4001":"-989",
    "unionPReportHarvestCP4016":"-989",
    "unionPReportHarvestCP5001":"-989",
    "unionPReportHarvestCP5016":"-989",
    "unionPReportHarvestCP6005":"-989",
    "unionPReportHarvestCP6006":"-989",
    "unionPReportHarvestRP0001":"-989",
    "unionPReportHarvestRP0004":"-989",
    "unionPReportHarvestRP0007":"-989",
    "unionPReportHarvestRP0017":"-989",
    "unionPReportHarvestRP0018":"-989",
    "unionPReportHarvestRP0019":"-989",
    "unionPReportHarvestRP0033":"-989",
    "yiBaoBankConfirmStatus":"BIND_SUCCESS"
}


# 获取总个数
def get_count():
    fur_url = url +'10'
    req1 = requests.get(fur_url, headers=headers)
    temp = req1.json()
    count = str(temp['data']['count'])
    print('总个数为：' + count)
    an_save_txt(file,'总个数为：' + count)
    return(count)


def risk_data(p):
    fur_url = url + p
    data = []
    req1 = requests.get(fur_url, headers=headers)
    temp = req1.json()
    #print(temp)
    info = temp['data']['list']
    for name in info:
        nameCn = name['nameCn']
        nameEn = name['nameEn']
        dataTypeName = name['dataTypeName']
        data.append(nameEn + '---->' + nameCn + '---->' + dataTypeName)
    return data


def data_to_excel():
    fur_url = url + get_count()
    data = []
    req1 = requests.get(fur_url, headers=headers)
    temp = req1.json()
    #print(temp)
    info = temp['data']['list']
    i = 1
    for name in info:
        row = []
        nameCn = name['nameCn']
        nameEn = name['nameEn']
        dataTypeName = name['dataTypeName']
        row.append(str(i))
        row.append(nameEn)
        row.append(nameCn)
        row.append(dataTypeName)
        data.append(row)
        i += 1
    #print(data)
    data.sort()
    #row_commonWrite(data,'E:\zenglingwei\\test\\','credit-prod.xls','test')


# 规则引擎字段不在上传字段里面（list）
def get_param(file):
    base_list = []
    for key in info:
        base_list.append(key)
    params = open(file, 'r', encoding='utf-8')
    for line in params.readlines():
        param = line.split('	')[0]
        if param not in base_list and param!='appId':
            print("传入规则引擎缺失字段：",param)


# 获取规则引擎参数存储到txt
def main():
    count = get_count()
    data = risk_data(count)
    data.sort()                  # reverse = True 降序， reverse = False 升序（默认）
    i = 1
    for info in data:
        print(str(i)+'：' + info)
        an_save_txt(file,str(i)+'：' + info)
        i += 1


if __name__ == '__main__':
    file = 'E:\zenglingwei\\test\credit.txt'
    #main()
    #data_to_excel()
    #get_nameEn()
    #find_key()
    get_param('E:\zenglingwei\\test\\risk_param.txt')